import { useUserInfoStore } from '@/stores/userInfo.js'

export default {
    mounted(el, binding) {
        const userStore = useUserInfoStore()
        const value = binding.value  // 期望权限点或角色数组

        let hasPermission = false

        if (Array.isArray(value)) {
            hasPermission = value.some(v =>
                userStore.roles.includes(v) || userStore.permissions.includes(v)
            )
        } else {
            hasPermission = userStore.roles.includes(value) || userStore.permissions.includes(value)
        }

        if (!hasPermission) {
            el.parentNode && el.parentNode.removeChild(el)
        }
    }
}
